import functools


from abc import abstractproperty, ABCMeta, abstractmethod, ABC


# class EnabledMixin(metaclass=ABCMeta):
#     @property
#     @abstractmethod
#     def enabled(self):
#         pass
#
#     @enabled.setter
#     @abstractmethod
#     def enabled(self, val):
#         pass
#
#     def set_enabled(self, f):
#         @functools.wraps(f)
#         def decorator(f):
#             self.enabled = f
#             return f
#
#         return decorator


# class FlowEventMixin(metaclass=ABCMeta):
#
#     @property
#     @abstractmethod
#     def before_events(self):
#         pass
#
#     @property
#     @abstractmethod
#     def after_events(self):
#         pass
#
#     def before(self, f):
#         @functools.wraps(f)
#         def wrapper(*args, **kw):
#             return f(*args, **kw)
#
#         self.before_events.append(wrapper)
#         return wrapper
#
#     def after(self, f):
#         @functools.wraps(f)
#         def wrapper(*args, **kw):
#             return f(*args, **kw)
#
#         self.after_events.append(wrapper)
#         return wrapper
#
#     def exec_before(self, *args, **kwargs):
#         for f in self.before_events:
#             f(*args, **kwargs)
#
#     def exec_after(self, *args, **kwargs):
#         for f in self.after_events:
#             f(*args, **kwargs)
#
#
# class RoleSourceMixin(metaclass=ABCMeta):
#     @property
#     @abstractmethod
#     def role_config(self):
#         pass
#
#     @role_config.setter
#     @abstractmethod
#     def role_config(self, val):
#         pass
#
#     @property
#     def rid(self) -> int:
#         return self.role_config() if self.role_config else None
#
#
# class UserSourceMixin(metaclass=ABCMeta):
#
#     @property
#     @abstractmethod
#     def user_config(self):
#         pass
#
#     @user_config.setter
#     @abstractmethod
#     def user_config(self, val):
#         pass
#
#     @property
#     def uid(self) -> int:
#         return self.user_config() if self.user_config else None


from abc import ABCMeta, abstractclassmethod, abstractproperty, abstractmethod

from flow_alchemy.db.work_status import UserAction


class CaseAction:
    def __init__(self, parent):
        self.parent = parent

    def __getattribute__(self, item):
        if hasattr(UserAction, item):
            action = getattr(UserAction, item)

            def inner(*nodes):
                self.parent.case_action(action, *nodes)

            return inner
        else:
            return super(CaseAction, self).__getattribute__(item)
        # raise AttributeError("'{}' object has no attribute '{}'".format(type(self).__name__, item))



